package me.bcloud.web.servlet.manager;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import me.bcloud.web.domain.JobConfig;
import me.bcloud.web.service.JobConfigService;

@Controller
public class EditServlet extends HttpServlet {

	@Resource
	private JobConfigService jobConfigService;
	
	public void setJobConfigService(JobConfigService jobConfigService) {
		this.jobConfigService = jobConfigService;
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		JobConfig newjobConfig=new JobConfig();
		response.setContentType("text/html");
		try {
			BeanUtils.populate(newjobConfig, request.getParameterMap());
			jobConfigService.edit(newjobConfig);
			response.getOutputStream().write("ok".getBytes());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			response.getOutputStream().write("error".getBytes());
		}
		
	}
}
